package com.umeng.analytics.pro;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

public class cz extends df {
    public static class a implements dh {
        private final long a;

        public a() {

            this.a = -1;
        }

        public a(int arg3) {

            this.a = ((long) arg3);
        }

        public df a(dt arg5) {
            return new cz(arg5, this.a);
        }
    }

    class b {
        public static final byte a = 1;
        public static final byte b = 2;
        public static final byte c = 3;
        public static final byte d = 4;
        public static final byte e = 5;
        public static final byte f = 6;
        public static final byte g = 7;
        public static final byte h = 8;
        public static final byte i = 9;
        public static final byte j = 10;
        public static final byte k = 11;
        public static final byte l = 12;

        private b() {

        }
    }

    byte[] a;
    byte[] b;
    byte[] c;
    private static final dk d;
    private static final da e;
    private static final byte[] f;
    private static final byte h = -126;
    private static final byte i = 1;
    private static final byte j = 31;
    private static final byte k = -32;
    private static final int l = 5;
    private ce m;
    private short n;
    private da o;
    private Boolean p;
    private final long q;
    private byte[] r;

    static {
        d = new dk("");
        e = new da("", (byte) 0, (short) 0);
        byte[] v0 = new byte[16];
        f = v0;
        v0[0] = 0;
        f[2] = 1;
        f[3] = 3;
        f[6] = 4;
        f[8] = 5;
        f[10] = 6;
        f[4] = 7;
        f[11] = 8;
        f[15] = 9;
        f[14] = 10;
        f[13] = 11;
        f[12] = 12;
    }

    public cz(dt arg3) {
        this(arg3, -1);
    }

    public cz(dt arg5, long arg6) {
        super(arg5);
        this.m = new ce(15);
        this.n = 0;
        this.o = null;
        this.p = null;
        this.a = new byte[5];
        this.b = new byte[10];
        this.r = new byte[1];
        this.c = new byte[1];
        this.q = arg6;
    }

    public ByteBuffer A() throws cm {
        ByteBuffer v0_1;
        int v0 = this.E();
        this.f(v0);
        if (v0 == 0) {
            v0_1 = ByteBuffer.wrap(new byte[0]);
        } else {
            byte[] v1 = new byte[v0];
            this.g.d(v1, 0, v0);
            v0_1 = ByteBuffer.wrap(v1);
        }

        return v0_1;
    }

    public void B() {
        this.m.c();
        this.n = 0;
    }

    private int E() throws cm {
        int v2;
        int v1;
        int v7 = 128;
        int v0 = 0;
        if (this.g.h() >= 5) {
            byte[] v3 = this.g.f();
            int v4 = this.g.g();
            v1 = 0;
            v2 = 0;
            while (true) {
                v2 |= (v3[v4 + v0] & 127) << v1;
                if ((v3[v4 + v0] & 128) != v7) {
                    break;
                }

                v1 += 7;
                ++v0;
            }

            this.g.a(v0 + 1);
        } else {
            v1 = 0;
            while (true) {
                v2 = this.u();
                v1 |= (v2 & 127) << v0;
                if ((v2 & 128) != v7) {
                    break;
                }

                v0 += 7;
            }

            v2 = v1;
        }

        return v2;
    }

    private long F() throws cm {
        int v1;
        int v10 = 128;
        int v0 = 0;
        long v2 = 0;
        if (this.g.h() >= 10) {
            byte[] v4 = this.g.f();
            int v5 = this.g.g();
            v1 = 0;
            while (true) {
                v2 |= (((long) (v4[v5 + v0] & 127))) << v1;
                if ((v4[v5 + v0] & 128) != v10) {
                    break;
                }

                v1 += 7;
                ++v0;
            }

            this.g.a(v0 + 1);
        } else {
            while (true) {
                v1 = this.u();
                v2 |= (((long) (v1 & 127))) << v0;
                if ((v1 & 128) == v10) {
                    v0 += 7;
                    continue;
                }
                return v2;
            }
        }
        return v2;
    }

    private long a(byte[] arg9) {
        return ((((long) arg9[7])) & 255) << 56 | ((((long) arg9[6])) & 255) << 48 | ((((long) arg9[5])) & 255) << 40 | ((((long) arg9[4])) & 255) << 32 | ((((long) arg9[3])) & 255) << 24 | ((((long) arg9[2])) & 255) << 16 | ((((long) arg9[1])) & 255) << 8 | (((long) arg9[0])) & 255;
    }

    private void a(long arg8, byte[] arg10, int arg11) {
        arg10[arg11] = ((byte) (((int) (arg8 & 255))));
        arg10[arg11 + 1] = ((byte) (((int) (arg8 >> 8 & 255))));
        arg10[arg11 + 2] = ((byte) (((int) (arg8 >> 16 & 255))));
        arg10[arg11 + 3] = ((byte) (((int) (arg8 >> 24 & 255))));
        arg10[arg11 + 4] = ((byte) (((int) (arg8 >> 32 & 255))));
        arg10[arg11 + 5] = ((byte) (((int) (arg8 >> 40 & 255))));
        arg10[arg11 + 6] = ((byte) (((int) (arg8 >> 48 & 255))));
        arg10[arg11 + 7] = ((byte) (((int) (arg8 >> 56 & 255))));
    }

    private void a(da arg3, byte arg4) throws cm {
        if (arg4 == -1) {
            arg4 = this.e(arg3.b);
        }

        if (arg3.c <= this.n || arg3.c - this.n > 15) {
            this.b(arg4);
            this.a(arg3.c);
        } else {
            this.d(arg3.c - this.n << 4 | arg4);
        }

        this.n = arg3.c;
    }

    public void a(short arg2) throws cm {
        this.b(this.c(arg2));
    }

    private void a(byte[] arg2, int arg3, int arg4) throws cm {
        this.b(arg4);
        this.g.b(arg2, arg3, arg4);
    }

    public void a() throws cm {
    }

    public void a(byte arg1) throws cm {
        this.b(arg1);
    }

    protected void a(byte arg3, int arg4) throws cm {
        if (arg4 <= 14) {
            this.d(arg4 << 4 | this.e(arg3));
        } else {
            this.d(this.e(arg3) | 240);
            this.b(arg4);
        }
    }

    public void a(double arg6) throws cm {
        byte[] v0 = new byte[]{0, 0, 0, 0, 0, 0, 0, 0};
        this.a(Double.doubleToLongBits(arg6), v0, 0);
        this.g.b(v0);
    }

    public void a(int arg2) throws cm {
        this.b(this.c(arg2));
    }

    public void a(long arg4) throws cm {
        this.b(this.c(arg4));
    }

    public void a(da arg3) throws cm {
        if (arg3.b == 2) {
            this.o = arg3;
        } else {
            this.a(arg3, (byte) -1);
        }
    }

    public void a(db arg3) throws cm {
        this.a(arg3.a, arg3.b);
    }

    public void a(dc arg3) throws cm {
        if (arg3.c == 0) {
            this.d(0);
        } else {
            this.b(arg3.c);
            this.d(this.e(arg3.a) << 4 | this.e(arg3.b));
        }
    }

    public void a(dd arg2) throws cm {
        this.b(-126);
        this.d(arg2.b << 5 & -32 | 1);
        this.b(arg2.c);
        this.a(arg2.a);
    }

    public void a(String arg4) throws cm {
        try {
            byte[] v0_1 = arg4.getBytes("UTF-8");
            this.a(v0_1, 0, v0_1.length);
            return;
        } catch (UnsupportedEncodingException v0) {
            throw new cm("UTF-8 not supported!");
        }
    }

    public void a(dj arg3) throws cm {
        this.a(arg3.a, arg3.b);
    }

    public void a(dk arg3) throws cm {
        this.m.a(this.n);
        this.n = 0;
    }

    public void a(ByteBuffer arg5) throws cm {
        this.a(arg5.array(), arg5.position() + arg5.arrayOffset(), arg5.limit() - arg5.position());
    }

    public void a(boolean arg4) throws cm {
        byte v1 = 2;
        byte v0 = 1;
        if (this.o != null) {
            da v2 = this.o;
            if (!arg4) {
                v0 = v1;
            }

            this.a(v2, v0);
            this.o = null;
        } else {
            if (!arg4) {
                v0 = v1;
            }

            this.b(v0);
        }
    }

    private void b(byte arg3) throws cm {
        this.r[0] = arg3;
        this.g.b(this.r);
    }

    private void b(int arg6) throws cm {
        int v0;
        for (v0 = 0; (arg6 & -128) != 0; ++v0) {
            this.a[v0] = ((byte) (arg6 & 127 | 128));
            arg6 >>>= 7;
        }

        this.a[v0] = ((byte) arg6);
        this.g.b(this.a, 0, v0 + 1);
    }

    private void b(long arg10) throws cm {
        int v0;
        for (v0 = 0; (-128 & arg10) != 0; ++v0) {
            this.b[v0] = ((byte) (((int) (127 & arg10 | 128))));
            arg10 >>>= 7;
        }

        this.b[v0] = ((byte) (((int) arg10)));
        this.g.b(this.b, 0, v0 + 1);
    }

    public void b() throws cm {
        this.n = this.m.a();
    }

    private int c(int arg3) {
        return arg3 << 1 ^ arg3 >> 31;
    }

    private long c(long arg6) {
        return arg6 << 1 ^ arg6 >> 63;
    }

    private boolean c(byte arg4) {
        boolean v0 = true;
        int v1 = arg4 & 15;
        if (v1 != 1 && v1 != 2) {
            v0 = false;
        }

        return v0;
    }

    public void c() throws cm {
    }

    private void d(int arg2) throws cm {
        this.b(((byte) arg2));
    }

    private byte d(byte arg4) throws dg {
        switch (((byte) (arg4 & 15))) {
            case 0: {
                return 0;
            }
            case 1:
            case 2: {
                return 2;
            }
            case 3: {
                return 3;
            }
            case 4: {
                return 6;
            }
            case 5: {
                return 8;
            }
            case 6: {
                return 10;
            }
            case 7: {
                return 4;
            }
            case 8: {
                return 11;
            }
            case 9: {
                return 15;
            }
            case 10: {
                return 14;
            }
            case 11: {
                byte v0 = 13;
                return v0;
            }
            case 12: {
                return 12;
            }
        }

        throw new dg("don\'t know what type: " + (((byte) (arg4 & 15))));
    }

    private long d(long arg6) {
        return arg6 >>> 1 ^ -(1 & arg6);
    }

    public void d() throws cm {
        this.b(0);
    }

    private byte e(byte arg2) {
        return f[arg2];
    }

    private byte[] e(int arg4) throws cm {
        byte[] v0;
        if (arg4 == 0) {
            v0 = new byte[0];
        } else {
            v0 = new byte[arg4];
            this.g.d(v0, 0, arg4);
        }

        return v0;
    }

    public void e() throws cm {
    }

    private void f(int arg5) throws dg {
        if (arg5 < 0) {
            throw new dg("Negative length: " + arg5);
        }

        if (this.q != -1 && (((long) arg5)) > this.q) {
            throw new dg("Length exceeded max allowed: " + arg5);
        }
    }

    public void f() throws cm {
    }

    private int g(int arg3) {
        return arg3 >>> 1 ^ -(arg3 & 1);
    }

    public void g() throws cm {
    }

    public dd h() throws cm {
        int v4 = -126;
        int v0 = this.u();
        if (v0 != v4) {
            throw new dg("Expected protocol id " + Integer.toHexString(v4) + " but got " + Integer.toHexString(v0));
        }

        v0 = this.u();
        byte v1 = ((byte) (v0 & 31));
        if (v1 != 1) {
            throw new dg("Expected version 1 but got " + v1);
        }

        return new dd(this.z(), ((byte) (v0 >> 5 & 3)), this.E());
    }

    public void i() throws cm {
    }

    public dk j() throws cm {
        this.m.a(this.n);
        this.n = 0;
        return d;
    }

    public void k() throws cm {
        this.n = this.m.a();
    }

    public da l() throws cm {
        da v0;
        byte v2 = this.u();
        if (v2 == 0) {
            v0 = e;
        } else {
            short v0_1 = ((short) ((v2 & 240) >> 4));
            v0_1 = v0_1 == 0 ? this.v() : ((short) (v0_1 + this.n));
            da v1 = new da("", this.d(((byte) (v2 & 15))), v0_1);
            if (this.c(v2)) {
                Boolean v0_2 = (((byte) (v2 & 15))) == 1 ? Boolean.TRUE : Boolean.FALSE;
                this.p = v0_2;
            }

            this.n = v1.c;
            v0 = v1;
        }

        return v0;
    }

    public void m() throws cm {
    }

    public dc n() throws cm {
        int v1 = this.E();
        int v0 = v1 == 0 ? 0 : this.u();
        return new dc(this.d(((byte) (v0 >> 4))), this.d(((byte) (v0 & 15))), v1);
    }

    public void o() throws cm {
    }

    public db p() throws cm {
        byte v1 = this.u();
        int v0 = v1 >> 4 & 15;
        if (v0 == 15) {
            v0 = this.E();
        }

        return new db(this.d(v1), v0);
    }

    public void q() throws cm {
    }

    public dj r() throws cm {
        return new dj(this.p());
    }

    public void s() throws cm {
    }

    public boolean t() throws cm {
        boolean v0 = true;
        if (this.p != null) {
            v0 = this.p.booleanValue();
            this.p = null;
        } else if (this.u() != 1) {
            v0 = false;
        }

        return v0;
    }

    public byte u() throws cm {
        byte v0;
        if (this.g.h() > 0) {
            v0 = this.g.f()[this.g.g()];
            this.g.a(1);
        } else {
            this.g.d(this.c, 0, 1);
            v0 = this.c[0];
        }

        return v0;
    }

    public short v() throws cm {
        return ((short) this.g(this.E()));
    }

    public int w() throws cm {
        return this.g(this.E());
    }

    public long x() throws cm {
        return this.d(this.F());
    }

    public double y() throws cm {
        byte[] v0 = new byte[8];
        this.g.d(v0, 0, 8);
        return Double.longBitsToDouble(this.a(v0));
    }

    public String z() throws cm {
        String v0;
        int v1 = this.E();
        this.f(v1);
        if (v1 == 0) {
            v0 = "";
        } else {
            try {
                if (this.g.h() >= v1) {
                    v0 = new String(this.g.f(), this.g.g(), v1, "UTF-8");
                    this.g.a(v1);
                } else {
                    v0 = new String(this.e(v1), "UTF-8");
                }
            } catch (UnsupportedEncodingException v0_1) {
                throw new cm("UTF-8 not supported!");
            }
        }

        return v0;
    }
}

